--Table TBL_CUSTOMER_CONTACT
exec('
IF EXISTS
      (SELECT *
         FROM tempdb.DBO.SYSOBJECTS O
        WHERE o.xtype IN (''U'') AND o.name = ''##contact'')
        DROP TABLE ##contact

SELECT  RECID AS CIF,CONTACT_TYPE,CONTACT_NUM into ##contact
FROM [SERVER16].[VPB_WHR2].DBO.VPB_CUSTOMER_CONTACT 
where recid in (select cif from TBL_CUSTOMER)')

IF EXISTS
      (SELECT *
         FROM DBO.SYSOBJECTS O
        WHERE o.xtype IN ('U') AND o.name = 'TBL_CUSTOMER_CONTACT')
        DROP TABLE TBL_CUSTOMER_CONTACT

select cif,[Land Line] as Land_line, Mobile, Office, Fax, Pager 
into TBL_CUSTOMER_CONTACT from 
(SELECT CIF,CONTACT_TYPE,CONTACT_NUM
FROM ##contact ) AS A
PIVOT
(MAX(contact_num) FOR contact_type IN ([Land Line],[Mobile],[Office],[Fax],[Pager])) AS PVT
where CIF in (select cif from TBL_CUSTOMER)


update a
set a.Land_line = b.landline,
a.Mobile = b.mobile,
a.office = b.office
from TBL_CUSTOMER_CONTACT  a, [SERVER74].[STAGING].[dbo].[SME_CUSTOMER_UPDATE] b
where a.CIF=b.recid